<template>
  <view class="MainBox">
    <view class="CardBox">
      <view class="title">选择您的身份</view>
      <view class="ContentBox" >
        <view v-for="(role, index) in roles"
              :key="index"
              :class="['roleItem', { selected: selectedIndex === index }]"
              @click="selectRole(index)">
          <image class="img" :src="role.img"></image>
          <view class="role">{{ role.name }}</view>
        </view>
      </view>
      <button class="btn" @click="confirmSelection">确定</button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      roles: [
        { name: '老人用户', img: '/static/images/select/oldMan.png' },
        { name: '普通用户', img: '/static/images/select/man.png' },
        { name: '志愿者用户', img: '/static/images/select/volunteer.png' }
      ],
      selectedIndex: 0 // 默认选择的索引
    }
  },
  methods: {
    selectRole(index) {
      this.selectedIndex = index;

    },
    confirmSelection() {
      console.log('selectedIndex:',this.selectedIndex);
      if(this.selectedIndex == 0){
        uni.navigateTo({ url: '/pages/elderlyInterface/elderly' });
      }
      if(this.selectedIndex ===1){
        uni.navigateTo({ url: '/pages/regularUser/regularUser' });
      }
      if(this.selectedIndex ===2){
        uni.navigateTo({ url: '/pages/volunteerInterface/service' });
      }
    }
  }
}
</script>

<style>
.MainBox{
  width: 100vw;
  height: 100vh;
  background-color: #F8E3B9;
  display: flex;
  justify-content: center;
  align-items: center;
}
.CardBox{
  width: 90vw;
  height: 80vh;
  background-color: white;
  border-radius: 20px;
  display: flex;
  align-items: center;
  flex-direction: column;
}
.title{
  font-size: 18px;
  color: black;
  margin-top: 40px;
  width: 80vw;
  margin-bottom: 20px;
  font-weight: 800;
}
.ContentBox{
  width: 80vw;
  margin-top: 20px;
  display: flex; flex-direction: column;
  align-items: center;
}
.roleItem{
  width: 80vw;
  height: 100px;
  align-items: center;
  border:solid 4px whitesmoke; /* 默认灰色边框 */
  border-radius: 20px;
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  cursor: pointer;
}
.roleItem.selected {
  border-color: #F2A378; /* 选中时橘色边框 */
}
.role{
  color: #91693A;
  font-weight: 800;
}
.img{
  width: 100px;
  height: 100px;
  margin-right: 40px;
  margin-left: 40px;
}
.btn{
  background-color:#F2A378;
  color: white;
  width: 80vw;
  border-radius: 30px;
  margin-top: 60px;
}
</style>
